﻿using EduAssess.Services;
using EduAssess.ViewModels;
using EduAssess.Views;
using LiteDB;
using Microsoft.Extensions.DependencyInjection;

namespace EduAssess;

public class Dependency
{
    private static readonly ServiceProvider Provider;

    static Dependency()
    {
        var services = new ServiceCollection();
        
        services.AddSingleton<MainViewModel>();
        services.AddSingleton<StartPageViewModel>();
        
        services.AddTransient<CreateTestPage>();
        services.AddTransient<TestPageViewModel>();
        services.AddTransient<TestListPageViewModel>();
        services.AddTransient<TestDialogWindowViewModel>();
        services.AddTransient<StatisticsPageViewModel>();

        services.AddSingleton<PageNavigationService>();
        services.AddSingleton<DialogService>();
        services.AddSingleton<TestService>();
        services.AddSingleton<TestState>();
        services.AddTransient<Repository>();

        services.AddSingleton(new LiteDatabase(@"TestData.db"));
        
        Provider = services.BuildServiceProvider();
    }

    public static T Resolve<T>() where T : notnull => Provider.GetRequiredService<T>();
}